package com.oncliedisk.administrator.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2015/12/7.
 */
public class HttpUtils {
    private static HttpUtils client = null;
    private HttpUtils() {
    //初始化

    }

    /**
     * 获取Http对象
     *
     * @return
     */
    public static HttpUtils getInstance() {
        synchronized (HttpUtils.class) {
            if (client == null) {
                client = new HttpUtils();
            }
            return client;
        }
    }
    public static Bitmap getBitmap(String path) throws IOException{

        URL url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestMethod("GET");
        if(conn.getResponseCode() == 200){
            InputStream inputStream = conn.getInputStream();
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            return bitmap;
        }
        return null;
    }

}
